package cn.czxy.web.servlet.person;


import cn.czxy.domain.Person;
import cn.czxy.domain.User;
import cn.czxy.service.person.PersonService;
import cn.itcast.servlet.BaseServlet;

/**
 * @author lixinghua@itcast.cn
 * @version 1.0
 * @date 2019/4/13
 */
public class PersonServlet extends BaseServlet {
    /**获取service对象*/
    private PersonService service = new PersonService();

    /**
     * 添加用户信息
     * @return
     */
    public String addPerson(){
        Person bean = toBean(Person.class);
        User user = (User) getSession().getAttribute("user");
        bean.setUserName(user.getUserName());
        service.addPerson(bean);
        getSession().setAttribute("person",bean);
        return "redirect:/index.jsp";
//        return "redirect:/utils?method=send&callname="+bean.getCallname();
//        return "forward:/demand/top.jsp";
    }

    /**
     * 查询用户信息
     * @return
     */
    public String searchByUser(){
        User bean = (User) getSession().getAttribute("user");
        Person person= service.searchByUser(bean);
        getSession().setAttribute("person",person);
        return "redirect:/index.jsp";
    }
}
